package com.qys.livesMall.shop.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qys.livesMall.shop.modal.dto.task.app.child.SellTaskSaveChild;
import com.qys.livesMall.shop.modal.entity.ShopSellTaskProduct;
import com.qys.livesMall.shop.mapper.ShopSellTaskProductMapper;
import com.qys.livesMall.shop.service.ShopSellTaskProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 带货任务与店铺商品关联表 服务实现类
 * </p>
 *
 * @author
 * @since 2023-06-15
 */
@Service
public class ShopSellTaskProductServiceImpl extends ServiceImpl<ShopSellTaskProductMapper, ShopSellTaskProduct> implements ShopSellTaskProductService {

    @Override
    public void updateAndSave(Long shopSellTaskId, List<SellTaskSaveChild> goodsInfoList) {
        baseMapper.delete(Wrappers.<ShopSellTaskProduct>lambdaQuery().eq(ShopSellTaskProduct::getShopSellTaskId,shopSellTaskId));
        Set<ShopSellTaskProduct> set=new HashSet<>();
        goodsInfoList.forEach(e->{
            ShopSellTaskProduct shopSellTaskProduct = new ShopSellTaskProduct();
            shopSellTaskProduct.setShopSellTaskId(shopSellTaskId);
            shopSellTaskProduct.setShopGoodsInfoId(e.getShopGoodsInfoId());
            shopSellTaskProduct.setQuantitySold(e.getQuantitySold());
            set.add(shopSellTaskProduct);
        });
        saveBatch(set);
    }

    @Override
    public List<Long> listGoodsInfoIdBySellTaskId(Long sellTaskId) {
        return baseMapper.listGoodsInfoIdBySellTaskId(sellTaskId);
    }
}
